const Service = require('egg').Service;
module.exports = app => {
  return class IndexService extends Service {
    getIndexData(name = '', limit = 6) {
      return app.model.query(`
        select id,title,sub_title,publish_time,img,author from hy_article 
        where 
          type in (
            select id from hy_article_type 
            where parent_id = (
              select id from hy_article_type 
              where name = '${name}' and parent_id = 0 limit 1
            )
          ) ORDER BY publish_time DESC limit ${limit};
      `, {
        type: app.Sequelize.QueryTypes.SELECT
      });
    // return app.model.query(`select * from hy_article_type 
    // where name = '${name}' limit 1`, {
    //   raw: true,
    //   type: app.Sequelize.QueryTypes.SELECT
    // });
    }
  }
}